package com.woniuxy.service.impl;

import com.woniuxy.dao.OperationDao;
import com.woniuxy.entity.Operation;
import com.woniuxy.entity.PageBean;
import com.woniuxy.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperationServiceImpl implements OperationService {
    @Autowired
    OperationDao operationDao;

    @Override
    public PageBean<Operation> getOperationsByCondition(Operation operation, int pageIndex, int pageSize) {
        List<Operation> operations = operationDao.selectOperationByCondition(operation, pageIndex, pageSize);
        int totalRecord = operationDao.selectOperationCount(operation);
        PageBean pageBean = new PageBean(operations, pageIndex, pageSize, totalRecord);
        return pageBean;
    }

    @Override
    public PageBean<Operation> getOperationPageByDepartment(Operation operation, int pageIndex, int pageSize) {
        List<Operation> operations = operationDao.selectOperationByDepartment(operation, pageIndex, pageSize);
        int totalRecord = operationDao.selectOperationCountByDepartment(operation);
        PageBean pageBean = new PageBean(operations, pageIndex, pageSize, totalRecord);
        return pageBean;
    }

    @Override
    public PageBean<Operation> getOperationPageByOperationGrade(Operation operation, int pageIndex, int pageSize) {
        List<Operation> operations = operationDao.selectOperationByOperationGrade(operation, pageIndex, pageSize);
        int totalRecord = operationDao.selectOperationCountByOperationGrade(operation);
        PageBean pageBean = new PageBean(operations, pageIndex, pageSize, totalRecord);
        return pageBean;
    }
}
